package org.jsbd.boss.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.dao.ISimulatorLogDAO;
import org.jsbd.boss.dao.impl.ISimulatorActionLogDAO;
import org.jsbd.boss.domian.DMClientInfo;
import org.jsbd.boss.domian.channel.ChannelApkConfig;
import org.jsbd.boss.domian.channel.SimulatorActionLog;
import org.jsbd.boss.domian.channel.SimulatorLog;
import org.jsbd.boss.service.ApkManager;
import org.jsbd.boss.service.IApkSimulatorService;
import org.jsbd.boss.service.IChannelApkInfoService;
import org.jsbd.boss.service.ISimulatorLogService;
import org.jsbd.boss.service.SimulatorManager;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import edu.hziee.common.queue.DelayExecuteBuffer;

@Service
public class SimulatorLogServiceImpl implements ISimulatorLogService {
	public static final Logger LOGGER = LoggerFactory.getLogger(SimulatorLogServiceImpl.class);

	@Resource
	private ISimulatorLogDAO simulatorLogDAO;



	@Resource
	private IApkSimulatorService apkSimulatorService;

	@Resource
	private DelayExecuteBuffer<SimulatorLog> simulatorLogBuffer;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.ISimulatorLogService#addSimulatorLog(org.jsbd.boss
	 * .domian.DMClientInfo)
	 */
	@Override
	public void addSimulatorLog(DMClientInfo clientInfo) {
		SimulatorLog record = new SimulatorLog();
		String uuid = clientInfo.getUuid();
		if (StringUtils.isBlank(uuid)) {
			record.setUuid("1111111111");
		} else {
			record.setUuid(uuid);
		}
		record.setActionType(clientInfo.getActionType());
		record.setImsi(clientInfo.getImsi());
		record.setMark(clientInfo.getMark());
		record.setTaskType(clientInfo.getTaskType());
		record.setActionStatus(clientInfo.getStatus());
		record.setCurrentDate(DateUtil.getCurrentDateStr());
		record.setSysVer(apkSimulatorService.getVer(clientInfo.getMark()));
		record.setLoginType(clientInfo.getLoginType());
		record.setImei(clientInfo.getImei());
		record.setProvinceId(clientInfo.getProvince());
		record.setBase(clientInfo.getBase());
		record.setSms(clientInfo.getLoginCode());
		record.setHostAndPort(clientInfo.getHostAndPort());
		record.setScript(clientInfo.getScript());
		record.setBrushId(clientInfo.getBrushId());
		record.setHsman(clientInfo.getHsman());
		record.setHstype(clientInfo.getHstype());
		simulatorLogBuffer.add(record);
	}

	@Override
	public SimulatorLog selectSimulatorLog(SimulatorLog simulaorLog) {
		return simulatorLogDAO.selectSimulatorLog(simulaorLog);
	}

}
